Código fuente de 'Correo Cdonts.asp'

<html>
<head>
<title>Correo Cdonts - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
</head>
<body style="font-family: Arial; font-size: 11pt">
<p align="center"><b><font size="3">Correo Cdonts </font></b>

<p align="left">Ejemplo de configuración de correo con CDONTS (necesitas tenerlo 
instalado para que funcione, muchos servidores web lo proporcionan). <b><br>
<br>
Atención:</b> 
esta función está deshabilitada para enviar el envío masivo de correos desde 
este formulario. Mejor copia el código en tu página y envía desde allí.

<%
' Email object
Dim objCDONTS                 
' From persons' real name
Dim strFromName               
' Email addresses
Dim strFromEmail, strToEmail  
' Mensaje
Dim strSubject, strBody       
' La URL de esta página
Dim strThisPage               
' La Url de la página referida
Dim strReferringPage          
' Booleano que indica parámetros válidos
Dim bValidInput               

' Retrieve this page name and referring page name
strThisPage      = Request.ServerVariables("SCRIPT_NAME")
strReferringPage = Request.ServerVariables("HTTP_REFERER")

' Debugging lines:
'Response.Write strThisPage & "<BR>" & vbCrLf
'Response.Write strReferringPage & "<BR>" & vbCrLf

' Read in and set the initial values of our message parameters
strFromName  = Trim(Request.Form("txtFromName"))
strFromEmail = Trim(Request.Form("txtFromEmail"))
strToEmail   = Trim(Request.Form("txtToEmail"))
strSubject   = "Check out ASP 101!"
strBody      = Trim(Request.Form("txtMessage"))


' I set the body message to a message that referenced the page the
' user arrived from.  This makes it great if you place a link to it
' from your different articles, but can be weird if people link in
' from other web sites.
If strBody = "" Then
	If strReferringPage = "" Or InStr(1, strReferringPage, "www.asp101.com", 1) = 0 Then
		strBody = ""
		strBody = strBody & "He encontrado una web que creo que te gustará ver:" & vbCrLf
		strBody = strBody & vbCrLf
		strBody = strBody & "   http://www.astalaweb.com" & vbCrLf
	Else
		strBody = ""
		strBody = strBody & "He encontrado un artículo que creo que te gustará ver:" & vbCrLf
		strBody = strBody & vbCrLf
		strBody = strBody & "   " & strReferringPage & vbCrLf
	End If
End If
	
' Quick validation just to make sure our parameters are somewhat valid
bValidInput = True
bValidInput = bValidInput And strFromName <> ""
bValidInput = bValidInput And IsValidEmail(strFromEmail)
bValidInput = bValidInput And IsValidEmail(strToEmail)

' If valid send email and show thanks, o/w show form
If bValidInput Then
	' Set up our email object and send the message
	Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
	objCDONTS.From    = strFromName & " <" & strFromEmail & ">"
	objCDONTS.To      = strToEmail
	objCDONTS.Subject = strSubject
	objCDONTS.Body    = strBody
	

	
' Atención borrar el apóstrofe de la línea de abajo para que el correo pueda ser enviado
'	objCDONTS.Send
	Set objCDONTS = Nothing
	


	
'Si quisiéramos controlar más nuestro mail, sabed que existen estas otras propiedades: 
'oMail.Cc = "yo@misitio.com" envía una copia (carbon copy) a la dirección que especifiquemos. 
'oMail.Bcc = "el@susitio.com" envía una copia "ciega" (blind carbon copy) que no aparece en la lista de destinatarios del mensaje. 
'oMail.Importance = 1 envía el mail con urgencia (0=Baja, 1=Normal, 2=Alta). 
'oMail.AttachFile "c:\MisDocumentos\archivo.doc", "Hoja de Gastos" adjunta el fichero "archivo.doc" con el nombre "Hoja de Gastos". 


	' Mensaje de gracias
	ShowThanksMsg
Else
	If "http://" & Request.ServerVariables("HTTP_HOST") & strThisPage = strReferringPage Then
		Response.Write "There's been an error.  Please check your entries:" & "<BR>" & vbCrLf
	End If
	' Show our information retrieval form
	ShowReferralForm strThisPage, strFromName, strFromEmail, strToEmail, strBody
End If
' End of page logic... subs and functions follow! 
%>


<%
' Subroutines and Functions that encapsulate some functionality
' and make the above code easier to write... and read.

' Comprueba la validez sintáctica del correo

' A quick email syntax checker.  It's not perfect,
' but it's quick and easy and will catch most of
' the bad addresses than people type in.


Function IsValidEmail(strEmail)
	Dim bIsValid
	bIsValid = True
	
	If Len(strEmail) < 5 Then
		bIsValid = False
	Else
		If Instr(1, strEmail, " ") <> 0 Then
			bIsValid = False
		Else
			If InStr(1, strEmail, "@", 1) < 2 Then
				bIsValid = False
			Else
				If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
					bIsValid = False
				End If
			End If
		End If
	End If

	IsValidEmail = bIsValid
End Function



' Formulario de entrada de datos
' I made this a function just to get it out of the
' logic and make it easier to read.  It just shows the
' form that asks for the input


Sub ShowReferralForm(strPageName, strFromName, strFromEmail, strToEmail, strBody)
	' I use script_name so users can rename this script witout having to change the code.
	%></p>
<%

'¡Vamos a mandar un mail!
Dim sDestintatario, sAsunto, sCuerpo
Dim oMail 'el objeto CDO

sAsunto="E-Mail de prueba desde ASP"

'Creamos el cuerpo con varias líneas para facilitar la lectura
sCuerpo = "Este es mi primer mensaje enviado desde ASP." & VbCrLf
sCuerpo = sCuerpo & "¡Acabaré gestionando una lista de correo algún día!" & VbCrLf
sCuerpo = sCuerpo & VbCrlf & VbCrLf & "¡Ah! Lo aprendí en www.aspfacil.com"

sDestinatario="alguien@algunsite.com"

'Enviamos el email
set oMail=Server.CreateObject("CDONTS.NewMail")

'Establecemos las propiedades del objeto
'Pon aquí tu nombre y dirección
oMail.From = "ASPFácil ejemplo de Mail " 
oMail.To = sDestinatario
oMail.Subject = sAsunto
oMail.Body = sCuerpo

' Enviamos el email, quitar el apóstrofe de abajo para que el correo se envíe
'oMail.Send

set oMail = nothing
Response.Write ("Mensaje enviado.")

end sub

%>


</p>


</body>
</html>